import java.security.MessageDigest;
import java.sql.Time;

import org.junit.jupiter.api.Test;

public class testMD5 {
	private static String[] hexDigits = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e","f" };

	public static void main(String[] args) throws Exception {
		String str = "abc123";
		String str1 = MD5Encode(str);
		System.out.println(str1);
	}

	public static String byteArrayTOHexDigitsString(byte[] b) {
    	StringBuffer sb = new StringBuffer();
    	for(int i = 0;i < b.length; i++) {
    		sb.append(buteTOHexDigitsString(b[i]));
    	}
    	return null;
    }
	
	public static String buteTOHexDigitsString(byte ss) {
		int n = ss;
		if(n < 0) {
			n+=256;
		}
		int d1 = n/16;
		int d2 = n%16;
		return hexDigits[d1]+hexDigits[d2];
	}
	
	public static String MD5Encode(String pwd) throws Exception{
		String result = null;
		try {
			result = new String(pwd);
			MessageDigest md = MessageDigest.getInstance("MD5");
			System.out.println("****************"+result);
			result = byteArrayTOHexDigitsString(md.digest(result.getBytes()));
			System.out.println("$$$$$$$$$$$$$44444"+result);
		}catch(Exception e) {
			e.printStackTrace();
		}
		System.out.println("#############"+result);
		return result;
	}
	
	@Test
	public void timmme() {
		System.out.println(new Time(System.currentTimeMillis()));
	}
}
